<%@ page import="beans.Employee" %>
<%@ page import="service.EmployeeService" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>公司用车管理系统（司机队长）- 个人中心</title>
  <style>
    /* 全局样式 */
    body {
      margin: 0;
      padding: 0;
      font-family: "Microsoft YaHei", Arial, sans-serif;
      background: #f0f2f5;
      color: #333;
      min-height: 100vh;
    }

    /* 头部样式 */
    .header {
      background: linear-gradient(135deg, #183a8a, #2450a7);
      color: #fff;
      font-size: 2rem;
      font-weight: bold;
      padding: 15px 0 15px 20px;
      letter-spacing: 2px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    }
    .header-right {
      display: flex;
      align-items: center;
      margin-right: 30px;
      font-size: 1rem;
    }
    .user-icon {
      width: 45px;
      height: 45px;
      border-radius: 50%;
      background: rgba(255,255,255,0.2);
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 1.8rem;
      margin-right: 15px;
      transition: all 0.3s ease;
    }
    .user-icon:hover {
      background: rgba(255,255,255,0.3);
      transform: scale(1.05);
    }
    .user-info {
      margin-right: 20px;
      color: #fff;
      font-size: 1.1rem;
    }
    .bell-icon {
      font-size: 1.4rem;
      margin-right: 20px;
      color: #fff;
      cursor: pointer;
      transition: transform 0.3s ease;
    }
    .bell-icon:hover {
      transform: scale(1.1);
    }
    .logout {
      color: #fff;
      text-decoration: none;
      margin-left: 15px;
      font-size: 1rem;
      padding: 8px 15px;
      border-radius: 20px;
      background: rgba(255,255,255,0.1);
      transition: all 0.3s ease;
    }
    .logout:hover {
      background: rgba(255,255,255,0.2);
      transform: translateY(-2px);
    }

    /* 主体容器 */
    .container {
      display: flex;
      min-height: calc(100vh - 70px);
    }

    /* 侧边栏样式 */
    .sidebar {
      width: 220px;
      background: linear-gradient(180deg, #183a8a, #2450a7);
      display: flex;
      flex-direction: column;
      padding-top: 10px;
      box-shadow: 2px 0 8px rgba(24,58,138,0.1);
    }
    .menu-item {
      color: #fff;
      padding: 18px 0 18px 32px;
      font-size: 1.15rem;
      cursor: pointer;
      border-left: 5px solid transparent;
      transition: all 0.3s ease;
      text-decoration: none;
      display: block;
      position: relative;
      overflow: hidden;
    }
    .menu-item.active, .menu-item:hover {
      background: rgba(255,255,255,0.1);
      border-left: 5px solid #fff;
      font-weight: bold;
      box-shadow: 0 4px 8px rgba(24,58,138,0.15);
    }
    .menu-item::after {
      content: '';
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 2px;
      background: #fff;
      transform: scaleX(0);
      transition: transform 0.3s ease;
    }
    .menu-item:hover::after {
      transform: scaleX(1);
    }

    /* 主内容区样式 */
    .main-content {
      flex: 1;
      background: #fff;
      border: 2px solid #3ba0e9;
      border-left: none;
      padding: 30px;
      overflow-y: auto;
    }

    /* 个人信息卡片样式 */
    .profile-card {
      background: white;
      border-radius: 12px;
      box-shadow: 0 4px 20px rgba(0,0,0,0.05);
      padding: 30px;
      margin-bottom: 30px;
      transition: transform 0.3s ease;
    }
    .profile-card:hover {
      transform: translateY(-5px);
    }
    .profile-header {
      display: flex;
      align-items: center;
      margin-bottom: 30px;
      padding-bottom: 20px;
      border-bottom: 1px solid #eee;
    }
    .profile-avatar {
      width: 120px;
      height: 120px;
      border-radius: 50%;
      background: linear-gradient(135deg, #183a8a 0%, #2450a7 100%);
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 3.5rem;
      margin-right: 30px;
      box-shadow: 0 4px 15px rgba(24,58,138,0.2);
      transition: all 0.3s ease;
    }
    .profile-avatar:hover {
      transform: scale(1.05);
      box-shadow: 0 6px 20px rgba(24,58,138,0.3);
    }
    .profile-name {
      font-size: 2rem;
      font-weight: bold;
      color: #183a8a;
      margin-bottom: 5px;
    }
    .profile-role {
      color: #666;
      font-size: 1.1rem;
      background: #f0f7ff;
      padding: 5px 15px;
      border-radius: 20px;
      display: inline-block;
    }
    .profile-info {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 25px;
      padding: 20px 0;
    }
    .info-group {
      background: #f8f9fa;
      padding: 15px 20px;
      border-radius: 8px;
      transition: all 0.3s ease;
    }
    .info-group:hover {
      background: #f0f7ff;
      transform: translateX(5px);
    }
    .info-label {
      font-weight: 600;
      color: #666;
      margin-bottom: 8px;
      font-size: 0.95rem;
    }
    .info-value {
      color: #333;
      font-size: 1.1rem;
    }

    /* 按钮样式 */
    .btn {
      padding: 10px 20px;
      border: none;
      border-radius: 25px;
      cursor: pointer;
      font-size: 1rem;
      text-decoration: none;
      display: inline-block;
      margin-right: 10px;
      transition: all 0.3s ease;
      font-weight: 500;
    }
    .btn-primary {
      background: linear-gradient(135deg, #183a8a 0%, #2450a7 100%);
      color: white;
      box-shadow: 0 4px 15px rgba(24,58,138,0.2);
    }
    .btn-primary:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(24,58,138,0.3);
    }
    .btn-warning {
      background: linear-gradient(135deg, #ffc107 0%, #ffb300 100%);
      color: #000;
      box-shadow: 0 4px 15px rgba(255,193,7,0.2);
    }
    .btn-warning:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(255,193,7,0.3);
    }

    /* 提示消息样式 */
    .alert {
      padding: 15px 20px;
      border-radius: 8px;
      margin-bottom: 25px;
      font-size: 1rem;
      display: flex;
      align-items: center;
      animation: slideIn 0.3s ease;
    }
    @keyframes slideIn {
      from {
        transform: translateY(-20px);
        opacity: 0;
      }
      to {
        transform: translateY(0);
        opacity: 1;
      }
    }
    .alert-success {
      background: #d4edda;
      color: #155724;
      border: 1px solid #c3e6cb;
    }
    .alert-danger {
      background: #f8d7da;
      color: #721c24;
      border: 1px solid #f5c6cb;
    }

    /* 模态框样式 */
    .modal {
      display: none;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0,0,0,0.5);
      z-index: 1000;
      animation: fadeIn 0.3s ease;
    }
    @keyframes fadeIn {
      from {
        opacity: 0;
      }
      to {
        opacity: 1;
      }
    }
    .modal-content {
      position: relative;
      background: #fff;
      margin: 8% auto;
      padding: 30px;
      width: 50%;
      max-width: 500px;
      border-radius: 12px;
      box-shadow: 0 10px 30px rgba(0,0,0,0.1);
      animation: slideUp 0.3s ease;
    }
    @keyframes slideUp {
      from {
        transform: translateY(50px);
        opacity: 0;
      }
      to {
        transform: translateY(0);
        opacity: 1;
      }
    }
    .modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 25px;
      padding-bottom: 15px;
      border-bottom: 1px solid #eee;
    }
    .modal-header h2 {
      margin: 0;
      color: #183a8a;
      font-size: 1.8rem;
    }
    .close {
      font-size: 28px;
      cursor: pointer;
      color: #666;
      transition: all 0.3s ease;
    }
    .close:hover {
      color: #333;
      transform: rotate(90deg);
    }
    .form-group {
      margin-bottom: 20px;
    }
    .form-group label {
      display: block;
      margin-bottom: 8px;
      color: #666;
      font-weight: 500;
    }
    .form-control {
      width: 100%;
      padding: 12px;
      border: 1px solid #ddd;
      border-radius: 8px;
      font-size: 1rem;
      transition: all 0.3s ease;
    }
    .form-control:focus {
      border-color: #183a8a;
      box-shadow: 0 0 0 3px rgba(24,58,138,0.1);
      outline: none;
    }
    .form-actions {
      margin-top: 30px;
      text-align: right;
    }
    .btn-secondary {
      background: #6c757d;
      color: white;
      box-shadow: 0 4px 15px rgba(108,117,125,0.2);
    }
    .btn-secondary:hover {
      background: #5a6268;
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(108,117,125,0.3);
    }

    /* 响应式设计 */
    @media (max-width: 1200px) {
      .profile-info {
        grid-template-columns: 1fr;
      }
    }
    @media (max-width: 900px) {
      .profile-header {
        flex-direction: column;
        text-align: center;
      }
      .profile-avatar {
        margin-right: 0;
        margin-bottom: 20px;
      }
      .modal-content {
        width: 90%;
        margin: 15% auto;
      }
    }
    @media (max-width: 600px) {
      .profile-card {
        padding: 20px;
      }
      .btn {
        width: 100%;
        margin-bottom: 10px;
      }
    }
  </style>
</head>
<body>
  <div class="header">
    <div>欢迎登录公司用车管理系统（司机队长）</div>
    <div class="header-right">
      <div class="user-icon">👤</div>
      <div class="user-info">账号：<%=session.getAttribute("username")%></div>
      <div class="bell-icon">🔔</div>
      <a href="${pageContext.request.contextPath}/LogoutServlet" class="logout">退出登录</a>
    </div>
  </div>

  <div class="container">
    <div class="sidebar">
      <a class="menu-item" href="DriversServlet?action=all3">系统首页</a>
      <a class="menu-item active" href="DriversServlet?action=all2">个人中心</a>
      <a class="menu-item" href="ShenqingServlet?action=all">我的待办</a>
      <a class="menu-item" href="UseOrderServlet?action=list">我处理的</a>
      <a class="menu-item" href="VehiclesServlet?action=all">全部车辆信息</a>
      <a class="menu-item" href="DriversServlet?action=all">全部司机信息</a>
    </div>

    <div class="main-content">

      
      <% if(request.getAttribute("error") != null) { %>
        <div class="alert alert-danger"><%=request.getAttribute("error")%></div>
      <% } %>
      <% if(request.getAttribute("message") != null) { %>
        <div class="alert alert-success"><%=request.getAttribute("message")%></div>
      <% } %>

      <%
        // 从session获取用户信息
        Employee employee = (Employee) session.getAttribute("user");
        if (employee == null) {
          // 如果session中没有用户信息，从数据库获取
          EmployeeService employeeService = new EmployeeService();
          String username = (String) session.getAttribute("username");
          if (username != null) {
            employee = employeeService.getEmployeeByID(Integer.parseInt(username));
            session.setAttribute("user", employee);
          }
        }
      %>

      <div class="profile-card">
        <div class="profile-header">
          <div class="profile-avatar"><%= employee != null ? employee.getEmployeeName().charAt(0) : "?" %></div>
          <div>
            <div class="profile-name"><%= employee != null ? employee.getEmployeeName() : "未知用户" %></div>
            <div class="profile-role">司机队长</div>
          </div>
        </div>
        
        <div class="profile-info">
          <div class="info-group">
            <div class="info-label">工号</div>
            <div class="info-value"><%= employee != null ? employee.getEmployeeID() : "未知" %></div>
          </div>
          <div class="info-group">
            <div class="info-label">姓名</div>
            <div class="info-value"><%= employee != null ? employee.getEmployeeName() : "未知" %></div>
          </div>
          <div class="info-group">
            <div class="info-label">性别</div>
            <div class="info-value"><%= employee != null ? employee.getGender() : "未知" %></div>
          </div>
          <div class="info-group">
            <div class="info-label">部门</div>
            <div class="info-value">司机部</div>
          </div>
          <div class="info-group">
            <div class="info-label">职位</div>
            <div class="info-value"><%= employee != null ? employee.getPosition() : "未知" %></div>
          </div>
          <div class="info-group">
            <div class="info-label">入职日期</div>
            <div class="info-value"><%= employee != null && employee.getHireDate() != null ? new java.text.SimpleDateFormat("yyyy-MM-dd").format(employee.getHireDate()) : "未知" %></div>
          </div>
          <div class="info-group">
            <div class="info-label">联系电话</div>
            <div class="info-value"><%= employee != null ? employee.getPhoneNumber() : "未知" %></div>
          </div>
          <div class="info-group">
            <div class="info-label">电子邮箱</div>
            <div class="info-value"><%= employee != null ? employee.getEmail() : "未知" %></div>
          </div>
        </div>
        
        <div style="margin-top: 20px; text-align: right;">
          <button class="btn btn-primary" onclick="showChangePasswordModal()">修改密码</button>
        </div>
      </div>
    </div>
  </div>

  <!-- 修改密码模态框 -->
  <div id="changePasswordModal" class="modal">
    <div class="modal-content">
      <div class="modal-header">
        <h2>修改密码</h2>
        <span class="close" onclick="closeChangePasswordModal()">&times;</span>
      </div>
      <form action="${pageContext.request.contextPath}/EmployeeServlet" method="post" class="form">
        <input type="hidden" name="action" value="changePassword">
        <input type="hidden" name="employeeId" value="<%= employee != null ? employee.getEmployeeID() : "" %>">
        
        <div class="form-group">
          <label for="oldPassword">原密码</label>
          <input type="password" id="oldPassword" name="oldPassword" class="form-control" required>
        </div>

        <div class="form-group">
          <label for="newPassword">新密码</label>
          <input type="password" id="newPassword" name="newPassword" class="form-control" required>
        </div>

        <div class="form-group">
          <label for="confirmPassword">确认新密码</label>
          <input type="password" id="confirmPassword" name="confirmPassword" class="form-control" required>
        </div>

        <div class="form-actions">
          <button type="submit" class="btn btn-primary">确认修改</button>
          <button type="button" class="btn btn-secondary" onclick="closeChangePasswordModal()">取消</button>
        </div>
      </form>
    </div>
  </div>

  <script>
    function showChangePasswordModal() {
      document.getElementById('changePasswordModal').style.display = 'block';
    }

    function closeChangePasswordModal() {
      document.getElementById('changePasswordModal').style.display = 'none';
    }

    // 点击模态框外部关闭
    window.onclick = function(event) {
      if (event.target == document.getElementById('changePasswordModal')) {
        closeChangePasswordModal();
      }
    }

    // 表单提交前验证密码
    document.querySelector('form[action*="changePassword"]').onsubmit = function(e) {
      const newPassword = document.getElementById('newPassword').value;
      const confirmPassword = document.getElementById('confirmPassword').value;
      
      if (newPassword !== confirmPassword) {
        alert('两次输入的密码不一致');
        e.preventDefault();
        return false;
      }
      return true;
    };
  </script>
</body>
</html>